using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using Microsoft.Ccr.Core;
using XcoAppSpaces.Contracts.Service;
using XcoAppSpaces.Contracts.Messaging;
using XcoAppSpaces.Contracts.Transport;
using XcoAppSpaces.Contracts.WorkerResolve;

namespace XcoAppSpaces.Contracts.Communication
{
	/// <summary>
	/// Events giving information about incoming and outgoing communication, e.g. for monitoring
	/// </summary>
	public interface ICommunicationEvents
	{
		//event Action<UnserializedMessageEventArgs> SerializingMessage;
		//event Action<UnserializedMessageEventArgs> MessageDeserialized;
		
		/// <summary>
		/// Event that is triggered before a message is sent. Contains the serialized message parts, address and name of the transport service.
		/// </summary>
		event Action<MessageEventArgs> OnSendingMessage;
		
		/// <summary>
		/// Event that is triggered after a message has been received. Contains the serialized message parts, address and name of the transport service.
		/// </summary>
		event Action<MessageEventArgs> OnMessageReceived;
		
		/// <summary>
		/// Event that is triggered when a request from a remote space is received to resolve a local worker, which is the case when "ConnectWorker"
		/// is called on the remote space. Contains information about who sent the resolve request, the identifier of the worker that should be resolved
		/// and the result which will be sent to the remote space.
		/// </summary>
		event Action<WorkerResolveEventArgs> OnWorkerResolved;
	}

	/// <summary>
	/// Event args for message events.
	/// </summary>
	public class MessageEventArgs
	{
		/// <summary>
		/// The message that is being sent or received, in serialized state.
		/// </summary>
		public XcoMessage Message { get; set; }

		/// <summary>
		/// The address where the message is sent / from where it has been received.
		/// </summary>
		public string Address { get; set; }

		/// <summary>
		/// The name of the used transport service.
		/// </summary>
		public string TransportServiceName{ get; set; }
	}

	/// <summary>
	/// Event args for the OnWorkerResolved event.
	/// </summary>
	public class WorkerResolveEventArgs
	{
		/// <summary>
		/// The identifier of the worker (built from workertype/workername) that should be resolved.
		/// </summary>
		public string WorkerIdentifier { get; set; }

		/// <summary>
		/// The address of the space that sent the resolve request.
		/// </summary>
		public string RemoteAddress { get; set; }

		/// <summary>
		/// The result that will be sent.
		/// </summary>
		public ResolveStatus Result { get; set; }
	}

	//public class UnserializedMessageEventArgs
	//{
	//    public RemoteMessage Message { get; set; }
	//    public CausalityContext Context { get; set; }
	//    public string Address { get; set; }
	//    public string TransportServiceName{ get; set; }
	//}
}
